 <style>
      
        div#dialog-form { display:block; }
        input.text { margin-bottom:12px; width:95%; padding: .4em; }
        fieldset { padding:0; border:0; margin-top:25px; }
        h1 { font-size: 1.2em; margin: .6em 0; }
        div#users-contain { width: 350px; margin: 20px 0; }
        div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; }
        div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; }
        .ui-dialog .ui-state-error { padding: .3em; }
        .validateTips { border: 1px solid transparent; padding: 0.3em; }
        select.error, textarea.error, input.error , label.error{
    color:#FF0000;
}
    </style>
<script type="text/javascript">
jQuery.validator.setDefaults({
	debug: true,
	success: "valid"
});
jQuery.extend(jQuery.validator.messages, {
	  required: "Champs vide...",
	  dateISO: "La date n'est pas valide...",	 
	  number: "Rentrez une somme valide..."
	});
 var currentIdIncident = null;
	function changeSituation(id){
		idSituation = $('#s_'+id).val();
		currentIdIncident = id;
//		alert(idSituation);
		if (idSituation != 4){
			$.ajax({
			 	type: "POST",
			  	url: '<?php echo $this->url(array('controller'=>'incident',
		                'action'=>'changesituation'));?>',
			 	data: { idSituation: idSituation, idIncident: currentIdIncident }
				}).done(function( ) {
					if (idSituation==2){
						//alert('plop');
						window.location.reload();
				}
					else{
						//alert('plop');
						$('#img_select_'+id).attr('style','');
					}
				});
			
		}
		else{
//			alert('plop');
			
			$( "#dialog-form" ).dialog( "open" );
			
		}
	}	
	$(function() {
		$( "#dateResolution" ).datepicker({
					dateFormat : "yy-mm-dd"

			});
    });
	

$(document).ready(function() {
	


	$("#dialog-form").dialog({
		
        autoOpen: false,
        height: 350,
        resizable : false,
        position: "top",
        width: 350,
        modal: true,
        buttons: [{
            id:"btn-accept",
            text: "Mettre a jour l'incident",
            click: function() {
        		if (validForm.valid()){
        			var dateResolution = $('#dateResolution').val(); 
                    var solution = $('#solution').val();
                    var cout = $('#cout').val();
                    $.ajax({
        			 	type: "POST",
        			  	url: '<?php echo $this->url(array('controller'=>'incident',
        		                'action'=>'changesituation'));?>',
        			 	data: { idSituation: 4, idIncident: currentIdIncident, dateResolution : dateResolution,solution : solution, cout:cout  }
                		
        				}).done(function() {
        					$('#sitTd_'+currentIdIncident).html('Resolu');
                            $( this ).dialog( "close" );  
        				});
        				$( this ).dialog( "close" );  
                  }
        		
        		else{
        			alert('Verifiez vos champs...');
        		}
                }},{
                  id:"btn-cancel",
                  text: "Annuler",
                  click: function() {
            	  $( this ).dialog( "close" );
              }}
              		]
       
    });
    

	$('#myTable').dataTable({
        "bJQueryUI": true,
			"sPaginationType": "full_numbers",
			"oLanguage": {
    	"sProcessing":     "Traitement en cours...",
        "sSearch":         "Rechercher&nbsp;:",
        "sLengthMenu":     "Afficher _MENU_ &eacute;l&eacute;ments",
        "sInfo":           "Affichage de l'&eacute;lement _START_ &agrave; _END_ sur _TOTAL_ &eacute;l&eacute;ments",
        "sInfoEmpty":      "Affichage de l'&eacute;lement 0 &agrave; 0 sur 0 &eacute;l&eacute;ments",
        "sInfoFiltered":   "(filtr&eacute; de _MAX_ &eacute;l&eacute;ments au total)",
        "sInfoPostFix":    "",
        "sLoadingRecords": "Chargement en cours...",
        "sZeroRecords":    "Aucun &eacute;l&eacute;ment &agrave; afficher",
        "sEmptyTable":     "Aucune donnée disponible dans le tableau",
        "oPaginate": {
            "sFirst":      "Premier",
            "sPrevious":   "Pr&eacute;c&eacute;dent",
            "sNext":       "Suivant",
            "sLast":       "Dernier"
        },
        "oAria": {
            "sSortAscending":  ": activer pour trier la colonne par ordre croissant",
            "sSortDescending": ": activer pour trier la colonne par ordre décroissant"
        }
			}
				});

	$("#btn-accept").attr('disabled','disabled');
var validForm = $("#formResolu").validate({
	  rules: {
  dateResolution: {
    required: true,
    dateISO: true
  },
  cout: {
	    required: true,
	    number: true
	  },
	  solution: {
		    required: true
		   
		  }
},success: function(){
	$("#btn-accept").removeAttr('disabled');
}
});


	
//	$('#myTable').find('input').each(
//			function(index,s){
//				$(this).click(function(){
//					var id = $(this).attr('id');
//					
//				});
//			}
//		);


} );
</script>

<table id="myTable" class="tablesorter">
<thead>
    <tr>
        <th>Date de la panne</th>
        <th>Materiel</th>
        <th>Nom du déclarant</th>
        <th>Type de panne</th>
        <th>Resume de la panne</th>
        <th>Situation</th>
        <th></th>
		

    </tr>
	</thead>
	<tbody>
	<?php foreach($this->listIncidents as $incident) : ?>
    <tr>
    	
        <td><?php echo $this->escape($incident->datePanne)?></td>
     <td><?php echo $this->escape($incident->nomMateriel." (".$incident->raccourciReseau.$incident->numeroPoste.")")?></td>
        <td><?php echo $this->escape($incident->nomEmploye)?></td>
        <td><?php $type=$this->escape($incident->typePanne);
        	if ($type=='L')
        		print 'Logiciel';
        	elseif ($type == 'M')
        		print 'Materiel';
        	else 
        		print 'Reseaux';
        ?></td>
        <td><?php echo $this->escape($incident->resumePanne)?></td>
        <td id="sitTd_<?php echo $incident->id?>"><?php echo $this->selectSituation->setAttrib('id', 's_'.$incident->id)->setValue($incident->idSituation)?><input style="margin-left:100px;" type='button' onclick= 'changeSituation(<?php echo $incident->id?>)'value='valider'/>
        <img id="img_select_<?php echo $incident->id?>" src=<?php echo $this->baseUrl()."/images/ok_logo.png"?> alt="okLogo" height="25px" style="display:none">
        </td>
        <td><a href="<?php echo $this->url(array('controller'=>'incident',
                'action'=>'update','id'=>$incident->id));?>">Modifier un incident</a></td>
        
        
        
    </tr>
<?php endforeach; ?>
</tbody>
</table>
<div id="dialog-form" title="Ajoutez les details de la situation résolue">
    <p class="validateTips">Tous les elements sont requis.</p>
 
    <form id="formResolu">
    <fieldset>
        <label for="dateResolution">Date de resolution</label>
        <input type="text" name="dateResolution" id="dateResolution" class="text ui-widget-content ui-corner-all" /><br />
        <label for="solution">Solution Utilisée</label>
        <input type="text" name="solution" id="solution" value="" class="text ui-widget-content ui-corner-all" /><br />
        <label for="cout">Cout de l'intervention (en €)</label>
        <input type="text" name="cout" id="cout" value="" class="text ui-widget-content ui-corner-all" />
    </fieldset>
    </form>
</div>
